<?php
declare (strict_types=1);

namespace app\index\controller;

use app\common\model\UserNotify as UserNotifyModel;
use think\facade\View;
use think\response\Json;

class UserNotify extends Base
{

    public function index()
    {
        return View::fetch();
    }


    public function getList(): Json
    {
        $param = $this->request->param();
        $list = UserNotifyModel::getPageList(['uid' => $this->user->id, 'part' => 1], '*', $param['page'], 20, false);
        $ids = [];
        foreach ($list['result'] as $v) {
            if (!$v->is_read) {
                $ids[] = $v->id;
            }
        }
        if (!empty($ids)) {
            $this->handle($ids);
        }
        return json($list);
    }

    public function handle($ids)
    {
        UserNotifyModel::update(['is_read' => 1], ['id' => $ids]);
    }

}

